#include "eventServer.h"

namespace sde {

    void EventServer::subscribe(std::string cmd, SubscribeFunction function) {
        if (subscribers.find(cmd) == subscribers.end())
            subscribers[cmd] = SubscribeFunctionList();
        subscribers[cmd].push_back(function);
    }

//     void EventServer::unsubscribe(std::string cmd, SubscribeFunction function) {
//         subscribers[cmd].remove(function);
//     }
    
    void EventServer::publish(std::string cmd, VarMap args) {
        if (subscribers.find(cmd) != subscribers.end()) {
            args["cmd"] = Var(cmd);
            for (SubscribeFunctionList::iterator i = subscribers[cmd].begin(); i != subscribers[cmd].end(); ++i) {
                (*i)(args);
            }
        }
    }
}
